package cn.news.xinhuanet.lottery.pool;

import org.apache.log4j.Logger;

import java.util.Vector;

/**
 * 奖品池
 * Created by xinhuanet on 16-2-4.
 */
public class PrizePool {

    private static final Logger LOGGER = Logger.getLogger(PrizePool.class);
    protected static Vector<Integer> prizes = new Vector<Integer>();
    private static Integer index = 0;


    /**
     * 放置奖项
     *
     * @param prize
     * @param index
     */
    public synchronized static void setPrize(Integer index, Integer prize) {
        prizes.add(index, prize);
    }

    public synchronized static Integer getPrize() {
        Integer index = PrizeIndex.getPrizeIndex(prizes.size());
        Integer prize = prizes.get(index);
        if (prize > 0) {
            //如果是奖品，则移除
            prizes.remove(prize);
            //移除奖品之后，下标依然会向后加1,奖品则会往前移一位，造成遗漏，因此此处下标前移一位
            PrizeIndex.setCurrentIndex(PrizeIndex.getCurrentIndex() - 1);
        }
        LOGGER.info(Thread.currentThread().getName() + ":" + prizes.size() + ":" + index + ":" + prize + ":" + (prize > 0 ? "获奖---------" : "谢谢参与"));
        return prize;
    }
    public  static Integer getPrizeSize() {
        return prizes.size();
    }
}
